<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<h:head>

	<title>mymsgro</title>
	<link rel="stylesheet" type="text/css" href="css/main.css" />
	<link rel="stylesheet" type="text/css" href="css/meniu.css" />
	<link rel="stylesheet" type="text/css" href="css/style.css" />

</h:head>
<h:body>

	<ui:include src="header.xhtml" />


	<h:panelGroup layout="block" id="content">
		<ui:include src="leftMenu.xhtml" />

		<h:panelGroup layout="block" id="contenRight">



			<f:event type="preRenderView"
				listener="#{bookTableData.preRenderView}" />


			<!--TABEL DE SEARCH !!!  -->
			<h:form>
				<h:panelGroup layout="block" styleClass="quickSearch">
					<h:commandButton style="width: 17px; margin-right: 17px;"
						image="resources/img/view-refresh.png"
						action="#{bookTableData.init}"></h:commandButton>

					<h:outputText value="Title: " styleClass="outputTextType" />
					<h:inputText value="#{bookTableData.textToSearch}"
						name="textToSearch"></h:inputText>
					<h:commandButton id="search" value="Search"
						actionListener="#{bookTableData.searchBook}"
						styleClass="searchButton">
					</h:commandButton>


				</h:panelGroup>

				<!--SFARSIT DE SEARCH  -->
				<h:panelGroup layout="block" styleClass="header"
					style="margin-top: 20px;">
					<ul>
						<li id="selected"><a>Books</a></li>
					</ul>

				</h:panelGroup>

				<h:panelGroup layout="block" styleClass="contentTab">



					<h:panelGroup rendered="#{bookTableData.deletion == true}"
						layout="block">
						<h:outputText value="Are you sure you want to delete?"
							styleClass="inputAreYouSure">
						</h:outputText>
						<h:commandButton value="Yes" action="#{bookTableData.delete}"></h:commandButton>
						<h:commandButton value="No" action="#{bookTableData.init}"></h:commandButton>
					</h:panelGroup>

					<h:outputText id="error" value="#{bookTableData.error}"
						styleClass="inputAreYouSure"></h:outputText>


					<!--  <h:outputText id="error" value="#{bookTableData.error}"></h:outputText> -->

					<p:dataTable id="dt" value="#{bookTableData.books}" var="carte"
						paginator="true" rows="5"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15">

						<p:column>
							<f:facet name="header">
								<h:outputText value="Title" />
							</f:facet>
							<h:outputText id="bookName" value="#{carte.book.name}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Author" />
							</f:facet>
							<h:outputText id="author" value="#{carte.book.author}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Year" />
							</f:facet>
							<h:outputText id="year" value="#{carte.book.year}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Status" />
							</f:facet>
							<h:outputText id="status" value="#{carte.book.status}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Domain" />
							</f:facet>

							<h:outputText id="domain" value="#{carte.domain.name}" />
						</p:column>

						<p:column>

							<f:facet name="header">
								<h:outputText value="Borrow" />
							</f:facet>
							<h:commandButton value="Borrow"
								disabled="#{carte.book.status == 'notAvailable' or empty carte.users}"
								actionListener="#{bookTableData.borrow(carte.book.id)}">
							</h:commandButton>

						</p:column>
						<p:column>

							<f:facet name="header">
								<h:outputText value="Send Email" />
							</f:facet>
							<h:commandButton style="width: 45px;"
								image="resources/img/mail.png"
								disabled="#{carte.book.status == 'notAvailable'}"
								actionListener="#{bookTableData.sendInformation(carte.book.id)}"></h:commandButton>

						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Waiting List" />
							</f:facet>

							<h:selectOneMenu disabled="#{empty carte.users}"
								styleClass="comboBoxStyle" value="#{carte.currentUser}">
								<f:selectItems value="#{carte.users}" var="user"
									itemLabel="#{user.firstname} #{user.lastname}"
									itemValue="#{user.id}" />
							</h:selectOneMenu>
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Return" />
							</f:facet>
							<h:commandButton value="Return"
								disabled="#{carte.book.status != 'notAvailable'}"
								actionListener="#{bookTableData.returned(carte.book.id)}">
							</h:commandButton>
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="History" />
							</f:facet>
							<h:commandButton style="width: 30px;" action="bookHistory.xhtml"
								image="resources/img/history.png"
								actionListener="#{bookTableData.viewHistory}">
								<f:attribute name="bookId" value="#{carte.book.id}" />
							</h:commandButton>
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Review" />
							</f:facet>
							<h:commandButton action="bookReview.xhtml" value="Review"
								actionListener="#{bookTableData.setReviewBook}">
								<f:attribute name="bookIdForReview" value="#{carte.book.id}" />
							</h:commandButton>
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="Delete" />
							</f:facet>
							<h:commandButton style="width: 30px;"
								image="resources/img/delete.png"
								actionListener="#{bookTableData.del(carte.book.id)}"></h:commandButton>
						</p:column>
					</p:dataTable>
					<br />
					<br />
					<br />
				</h:panelGroup>

				<!-- ADD DOMAIN ADD BOOK -->

				<h:panelGroup layout="block" styleClass="header"
					style="margin-top: 20px;">
					<ul>
						<li id="selected"><a>Add Book</a></li>
					</ul>
				</h:panelGroup>
				<h:panelGroup layout="block" styleClass="contentTabAddBook">
					<h:outputText id="errorAddBook" styleClass="inputAreYouSure"
						value="#{bookTableData.errorAddBook}"></h:outputText>
					<h:panelGrid columns="3" id="tables" styleClass="addDomain">
						<h:outputText value="Book Title" />
						<h:inputText value="#{bookTableData.myBook.name}" />
						<h:outputText value="*" styleClass="inputRed"></h:outputText>

						<h:outputText value="Author" />
						<h:inputText value="#{bookTableData.myBook.author}" />
						<h:outputText value="*" styleClass="inputRed"></h:outputText>

						<h:outputText value="Year" />
						<h:inputText value="#{bookTableData.testYear}" />
						<h:outputText value="*" styleClass="inputRed"></h:outputText>

						<h:outputText value="Domain"></h:outputText>
						<h:selectOneMenu value="#{bookTableData.myBook.idDomain}"
							styleClass="comboBoxStyle">
							<f:selectItems value="#{bookTableData.domains}" var="domain"
								itemLabel="#{domain.name}" itemValue="#{domain.id}" />
						</h:selectOneMenu>


					</h:panelGrid>
					<h:outputText value="*fields mandatory" styleClass="inputRedText"></h:outputText>
					<br />
					<h:commandButton value="Add Book" styleClass="butoaneAddBook2"
						actionListener="#{bookTableData.addBook}">
						<f:ajax execute="tables" render="@all"></f:ajax>
					</h:commandButton>

					<br />





				</h:panelGroup>




				<h:panelGroup layout="block" styleClass="header"
					style="margin-top: 20px;">
					<ul>
						<li id="selected"><a>Add Domain</a></li>
					</ul>
				</h:panelGroup>

				<h:panelGroup layout="block" styleClass="contentTabAddDomain">
					<h:outputText id="errorDomain" value="#{bookTableData.errorDomain}"
						styleClass="inputAreYouSure"></h:outputText>
					<h:panelGrid columns="3" id="addDomain" styleClass="addDomain">
						<h:outputText value="Domain"></h:outputText>
						<h:inputText id="addDomainInput"
							value="#{bookTableData.domain.name}"></h:inputText>
						<h:outputText value="*" styleClass="inputRed"></h:outputText>
					</h:panelGrid>

					<h:outputText value="*field mandatory" styleClass="inputRedText"></h:outputText>
					<br />
					<h:commandButton value="Add Domain" styleClass="butoaneDomain2"
						actionListener="#{bookTableData.addDomain}">
						<f:ajax execute="addDomain" render="@all"></f:ajax>
					</h:commandButton>


				</h:panelGroup>






			</h:form>
		</h:panelGroup>
	</h:panelGroup>

</h:body>
</html>